-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net,http2: refactor _write and _writev in net.Socket and http2.Http2Stream #20643
Conversation
I'm concerned about making the That logic needs tidy up anyway, so let's find a way to keep the number of arguments consistent. |
@mcollina You mean That said, please share whatever you have in mind and hopefully we would be able to make it a tad faster and simpler. |
My bad, I misread a |
That's what I did the first time around too 😅, but yeah. They're different functions, so I hope everything is fine, right? Should I proceed? |
A few questions:
-- more to come -- |
okay, tests pass so I'm keeping it here until someone asks me to remove it. One more thing: Why does this.once('connect', function connect() {
this._writeGeneric(writev, data, encoding, cb);
}); even though normal functions have their own |
Tests pass again, I'm either making progress, or we have weak test cases. Two things next:
|
Okay, when it comes to the actual logic for refreshing timers, they're both quite similar. In Socket.prototype._unrefTimer = function _unrefTimer() {
for (var s = this; s !== null; s = s._parent) {
if (s[kTimeout])
s[kTimeout][refreshFnSymbol]();
}
}; and in [kUpdateTimer]() {
if (this.destroyed)
return;
if (this[kTimeout])
this[kTimeout][refreshFnSymbol]();
if (this[kSession])
this[kSession][kUpdateTimer]();
} for now, the least I think I could do is switch from the iterative approach in |
Okay, it wasn't recursing, but rather refreshing the associated |
1732c4f
to
1257d56
Compare
Current roadblocks (inconsistencies):
|
Maybe something that we also want in HTTP/2? Anyway, this LGTM as is and I’d be okay with landing this as-is and iterating onwards from there. |
I haven't had a chance to fully review but 2 things off the top:
|
While we may not need the properties yet, I believe they could prove helpful while fleshing out future behavior. Anyway, let me know if the added cruft of two simple properties would be worth a little consistency and nifty properties that could be used in the future (or perhaps even right now).
While I think I could just move to a Symbol pretty easily, I don't think it should be a problem because:
That said, if you insist, I will make that change.
Again, I made the change only to make things a tad more consistent, and you have a much better idea that me how this could affect speed in the long term. If you say, I could revert that particular part back to the original. |
The fact that _writeGeneric is exposed on the Socket is just bad behaviour we're stuck with — it comes from a time when we didn't have many options for hiding private properties and methods. Now we do and since it's a private implementation detail, it shouldn't leak to the user. As for
I don't think things need to be more consistent between those two functions. I get the point of making _write and _writev more consistent, I don't think any unrelated functions need to be. As far as how it's slower: calling a function (adding it to the stack) is slower than just a loop and since it's now recursive there's no way it can get inlined by V8. |
Get it, loop would definitely be faster. That said, I'm thinking: as long as the two classes each have an exposed function (maybe called
It seems that'll no longer be a problem once I'm done with this (same with it being exposed on |
Keep in mind that there would be the same issue with exposing |
@apapirovski could we not expose it but still call it from a base class, somehow? |
@apapirovski @addaleax This looks better, I suppose? |
LGTM. Could also be a separate function to avoid the symbol lookup when calling it but this is fine as the first version. _unrefTimer still needs to be reverted. Then we could likely land this and iterate from there. |
@apapirovski reverting |
@BridgeAR okay! In that case, this is ready to merge. Awaiting @apapirovski's explicit approval before landing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for working on this!
@apapirovski Thanks for all the constructive feedback and guidance! Will land this today. |
Landing this. |
Refactor writable part (the _write and _writev functions) in net.Socket and http2.Http2Stream classes. Also involves adding a generic "WriteGeneric" method to the Http2Stream class based on net.Socket._writeGeneric, but behind a symbol.
Squashing and running CI, will land in the morning. |
9cf4830
to
334f044
Compare
Landed in a7fa0db |
Refactor writable part (the _write and _writev functions) in net.Socket and http2.Http2Stream classes. Also involves adding a generic "WriteGeneric" method to the Http2Stream class based on net.Socket._writeGeneric, but behind a symbol. PR-URL: #20643 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Refactor writable part (the _write and _writev functions) in net.Socket and http2.Http2Stream classes. Also involves adding a generic "WriteGeneric" method to the Http2Stream class based on net.Socket._writeGeneric, but behind a symbol. PR-URL: #20643 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Refactor writable part (the _write and _writev functions) in net.Socket and http2.Http2Stream classes. Also involves adding a generic "WriteGeneric" method to the Http2Stream class based on net.Socket._writeGeneric, but behind a symbol. PR-URL: nodejs#20643 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Refactor writable part (the _write and _writev functions) in net.Socket and http2.Http2Stream classes. Also involves adding a generic "WriteGeneric" method to the Http2Stream class based on net.Socket._writeGeneric, but behind a symbol. PR-URL: nodejs#20643 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Refactor writable part (the _write and _writev functions) in net.Socket and http2.Http2Stream classes. Also involves adding a generic "WriteGeneric" method to the Http2Stream class based on net.Socket._writeGeneric, but behind a symbol. PR-URL: nodejs#20643 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Refactor writable part (the _write and _writev functions) in net.Socket and http2.Http2Stream classes. Also involves adding a generic "WriteGeneric" method to the Http2Stream class based on net.Socket._writeGeneric, but behind a symbol. Backport-PR-URL: #22850 PR-URL: #20643 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesRoadmap
http2.Http2Stream._write
andhttp2.Http2Stream._writev
http2.Http2Stream._writeGeneric
net.Socket._writeGeneric
andhttp2.Http2Stream._writeGeneric
writeGeneric
frominternal/stream_base_commons
./cc @addaleax @nodejs/http2 @nodejs/net